package com.cskaoyan.controller;

import com.cskaoyan.bean.VO.*;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.service.AdminStatService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author:zhangjiaxin 统计报表
 **/
@RestController
@RequestMapping("admin/stat")
public class AdminStatController {

    @Autowired
    AdminStatService adminStatService;

    @RequiresPermissions("admin:stat:user")
    @RequestMapping("user")
    public BaseRespVo user(){
        AdminStatUserInnerVo[] innerVo = adminStatService.selectUser();
        AdminStatUserVo adminStatUserVo = new AdminStatUserVo();
        String[] columns=new String[2];
        columns[0]="day";
        columns[1]="users";
        adminStatUserVo.setColumns(columns);
        adminStatUserVo.setRows(innerVo);

        return BaseRespVo.ok(adminStatUserVo);
    }


    @RequiresPermissions("admin:stat:order")
    @RequestMapping("order")
    public BaseRespVo order(){
        AdminStatOrderInnerVo[] innerVo= adminStatService.selectOrder();
        AdminStatOrderVo adminStatOrderVo = new AdminStatOrderVo();
        String[] columns=new String[5];
        columns[0]="day";
        columns[1]="orders";
        columns[2]="customers";
        columns[3]="amount";
        columns[4]="pcr";
        adminStatOrderVo.setColumns(columns);
        adminStatOrderVo.setRows(innerVo);
        return BaseRespVo.ok(adminStatOrderVo);
    }


    @RequiresPermissions("admin:stat:goods")
    @RequestMapping("goods")
    public BaseRespVo goods(){
        AdminStatGoodsInnerVo[] innerVo= adminStatService.selectGoods();
        AdminStatGoodsVo adminStatGoodsVo = new AdminStatGoodsVo();
        String[] columns=new String[4];
        columns[0]="day";
        columns[1]="orders";
        columns[2]="products";
        columns[3]="amount";
        adminStatGoodsVo.setColumns(columns);
        adminStatGoodsVo.setRows(innerVo);
        return BaseRespVo.ok(adminStatGoodsVo);
    }
}
